#if !defined(__UPDATE_MANAGER_H)
#define __UPDATE_MANAGER_H

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include "Singleton.h"
#include "HttpConnection.h"

class UpdateManagerListener {
public:
	typedef UpdateManagerListener* Ptr;
	typedef vector<Ptr> List;
	typedef List::iterator Iter;
	enum Types {
		COMPLETE,
		FAIL
	};
	
	virtual void on(Types, int file) throw() = 0;
};

class UpdateManager : public Singleton<UpdateManager>, public Speaker<UpdateManagerListener>, private HttpConnectionListener {
public:
	UpdateManager() : currentlyUpdating(-1) {}
	virtual ~UpdateManager() {}
	friend class Singleton<UpdateManager>;
	enum Types { CLIENT, MYINFO, CLIENTVERSION, ISP };

	void reloadFile(int file);
	void updateFiles(StringIntMap& aUrls);

private:
	HttpConnection c;
	StringIntMap updatelist;
	int currentlyUpdating;
	void startDownload();
	string downBuf;

	// HttpConnectionListener
	virtual void on(HttpConnectionListener::Data, HttpConnection*, const u_int8_t*, int) throw();
	virtual void on(HttpConnectionListener::Complete, HttpConnection* /*conn*/, const string& aLine) throw();
	virtual void on(HttpConnectionListener::Failed, HttpConnection* /*conn*/, const string& aLine) throw();
};
#endif
/**
 * @file
 * $Id: UpdateManager.h 303 2005-08-18 23:46:43Z sulan $
 */